package com.aiolos.hadoop.hdfs;

public class WordCountMapperImpl implements ImoocMapper {


    @Override
    public void map(String line, ImoocContext context) {
        String[] words = line.split(" ");
        for (String word:words) {
            Object value = context.get(word);
            if(value == null){
                //表示没有出现过该单词
                context.write(word,1);
            }else {
                //出现过该单词，取出单词对应的次数再加1后保存回去
                int v = Integer.parseInt(value.toString());
                context.write(word,v+1);
            }
        }
    }
}
